﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using RoundupReadyPlusWPF.Pages;
using WpfPageTransitions;
using RoundupReadyPlusWPF.AppCode;

namespace RoundupReadyPlusWPF.Controls
{
    /// <summary>
    /// Interaction logic for StepNavigator.xaml
    /// </summary>
    public partial class StepNavigator : UserControl, IObserver<PageSwitcher>
    {
        public PageTransition PageNavigator {get;set;}

        private static Brush RedBrush = new SolidColorBrush(Color.FromArgb(0xFF,0x92,0x02,0x26));

        private static Brush GrayBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xbd, 0xbd, 0xbd));

        public StepNavigator()
        {
            InitializeComponent();
        }

        public StepNavigator(PageTransition pageTransition)
        {
            InitializeComponent();
            PageNavigator = pageTransition;
        }


        private void ShowPage(UserControl page)
        {
            if (page != null && PageNavigator != null)
            {
                PageNavigator.ShowPage(page);
            }
        }


        public void NextPage()
        {
            ShowPage(PageSwitcher.Instance.NextPage());
        }

        private void srRegion_Click(object sender, RoutedEventArgs e)
        {
            ShowPage(PageSwitcher.Instance.SelectPage(PageSwitcher.Pages.Region));
        }

        private void srState_Click(object sender, RoutedEventArgs e)
        {
            ShowPage(PageSwitcher.Instance.SelectPage(PageSwitcher.Pages.State));
        }

        private void srDistrict_Click(object sender, RoutedEventArgs e)
        {
            ShowPage(PageSwitcher.Instance.SelectPage(PageSwitcher.Pages.District));
           
        }

        private void srTown_Click(object sender, RoutedEventArgs e)
        {
            ShowPage(PageSwitcher.Instance.SelectPage(PageSwitcher.Pages.Town));
        }

        #region IObserver<PageSwitcher>

        public void OnCompleted()
        {
            // caso pare de observar mudança de página
        }

        public void OnError(Exception error)
        {
            // fica sem atualizar por algum erro no swtich da pagina
        }

        public void OnNext(PageSwitcher value)
        {
            // Atualiza o layout
            srRegion.IsEnabled = value.CurrentPage >= PageSwitcher.Pages.Region;
            srState.IsEnabled = value.CurrentPage >= PageSwitcher.Pages.State;
            srDistrict.IsEnabled = value.CurrentPage >= PageSwitcher.Pages.District;
            srTown.IsEnabled = value.CurrentPage >= PageSwitcher.Pages.Town;

            srRegion.IsChecked = srRegion.IsEnabled;
            srState.IsChecked = srState.IsEnabled;
            srDistrict.IsChecked = srDistrict.IsEnabled;
            srTown.IsChecked = srTown.IsEnabled;

            Line1.Fill = srRegion.IsEnabled ? RedBrush : GrayBrush;
            Line2.Fill = srState.IsEnabled ? RedBrush : GrayBrush;
            Line3.Fill = srDistrict.IsEnabled ? RedBrush : GrayBrush;
        }

        #endregion
    }
}
